package com.xxx.controller;


import com.xxx.pojo.Pingpai;
import com.xxx.service.PingpaiService;
import com.xxx.utils.RespBean;
import com.xxx.utils.RespPageBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * <p>
 *
 * </p)
 * @author lczcr
 * @description
 * @data 2022/11/4 12:41
*/
@RestController
@RequestMapping("/pingpaitest")
public class Pingpaiontroller {

    @Autowired
    private PingpaiService pingpaiService;


    @ApiOperation(value = "获取所有信息")
    @GetMapping("/")
    public RespPageBean getAllPingpai(@RequestParam(defaultValue = "1") Integer currentPage,
                                            @RequestParam(defaultValue = "10") Integer size,
                                            Pingpai pingpai){
        return pingpaiService.getPingpaiByPage(currentPage,size,pingpai);
    }


    @ApiOperation(value = "增加信息")
    @PostMapping("/")
    public RespBean addPingpai(@RequestBody Pingpai pingpai){
        if(pingpaiService.save(pingpai)){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }


    @ApiOperation(value = "更新信息")
    @PutMapping("/")
    public RespBean updatePingpai(@RequestBody Pingpai pingpai){
        if(pingpaiService.updateById(pingpai)){
            return RespBean.success("更新成功");
        }
        return RespBean.error("更新失败");
    }

    @ApiOperation(value = "批量删除")
    @DeleteMapping("/{id}")
    public RespBean deletePingpai(@RequestBody Pingpai pingpai){
        if(pingpaiService.removeById(pingpai)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }


    @ApiOperation(value = "单个删除")
    @DeleteMapping("/")
    public RespBean deletePingpaisByIds(Integer[] ids){
        if(pingpaiService.removeByIds(Arrays.asList(ids))){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

}
